home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FILES.SWG / 0049_Low Level File Routines.pas < prev    next >
Pascal/Delphi Source File  |  1994-02-09  |  30KB  |  525 lines

  1. UNIT FILEIO;            { Low Level File handling routines. Jan 18/94   }
  2.                         { Copyright (C) 1993,1994 Greg Estabrooks       }
  3.                         { NOTE: Requires TP 6.0+ to compile.            }
  4. INTERFACE
  5. {***********************************************************************}
  6. USES DOS;                       { IMPORT FSearch.                       }
  7. CONST                           { Handles PreDefined by DOS.            }
  8.      fStdIn     = $00;          { STD Input Device, (Keyboard).         }
  9.      fStdOut    = $01;          { STD Output Device,(CRT).              }
  10.      fStdErr    = $02;          { STD Error Device, (CRT).              }
  11.      fStdCom    = $03;          { STD Comm.                             }
  12.      fStdPrn    = $04;          { STD Printer.                          }
  13.      oRead      = $00;          { Opens a file for read only.           }
  14.      oWrite     = $01;          { Opens a file for writing only.        }
  15.      oReadWrite = $02;          { Opens a file for reading and writing. }
  16.      oDenyAll   = $10;          { Deny access to other processes.       }
  17.      oDenyWrite = $20;          { Deny write access to other processes. }
  18.      oDenyRead  = $30;          { Deny read access to other processes.  }
  19.      oDenyNone  = $40;          { Allow free access to other processes. }
  20.                                 { Possible file attribs,can be combined.}
  21.      aNormal   = $00;  aSystem = $04;  aArchive = $20;
  22.      aReadOnly = $01;  aVolume = $08;
  23.      aHidden   = $02;  aDir    = $10;
  24. TYPE
  25.     LockType = (Lock,UnLock);   { Ordinal Type for use with 'fLock'.    }
  26. VAR
  27.    fError  :WORD;               { Holds any error codes from routines.  }
  28.  
  29. PROCEDURE ASCIIZ( VAR fName :STRING );
  30.                          { Routine to add a NULL to a string to make it }
  31.                          { ASCIIZ compatible.                           }
  32.                          { File routines automatically call this routine}
  33.                          { usage :                                      }
  34.                          {  ASCIIZ(fName);                              }
  35.  
  36. FUNCTION  fCreate( fName :STRING; Attr :BYTE ) :WORD;
  37.                          { Routine to Create 'fName' with an attribute  }
  38.                          { of 'Attr'. If the file already exists then it}
  39.                          { will be truncated to a zero length file.     }
  40.                          { Returns a WORD value containing the  handle. }
  41.                          { Uses Int 21h/AH=3Ch.                         }
  42.                          { usage :                                      }
  43.                          {  handle := fCreate('Temp.Dat',aNormal);      }
  44.  
  45. FUNCTION  fOpen( fName :STRING; Mode :BYTE ) :WORD;
  46.                          { Routine to open already existing file defined}
  47.                          { in 'fName' with an opening mode of 'Mode'.   }
  48.                          { Returns a WORD value containing the  handle. }
  49.                          { Uses Int 21h/AH=3Dh.                         }
  50.                          { usage :                                      }
  51.                          {  handle := fOpen('Temp.Dat',oRead);          }
  52.  
  53. PROCEDURE fRead( fHandle :WORD; VAR Buff; NTRead:WORD; VAR ARead :WORD );
  54.                          { Reads 'NTRead' bytes of data from 'fHandle'  }
  55.                          { and puts it in 'Buff'. The actually amount   }
  56.                          { of bytes read is returned in 'ARead'.        }
  57.                          { Uses Int 21h/AH=3Fh.                         }
  58.                          { usage :                                      }
  59.                          {  fRead(handle,Buffer,SizeOf(Buffer),ARead);  }
  60.  
  61. PROCEDURE fWrite( fHandle :WORD; VAR Buff; NTWrite:WORD; VAR AWrite :WORD );
  62.                          { Writes 'NTWrite' bytes of info from 'Buff'   }
  63.                          { to 'fHandle'. The actually amount written is }
  64.                          { returned in 'AWrite'.                        }
  65.                          { Uses Int 21h/AH=40h.                         }
  66.                          { usage :                                      }
  67.                          {  fWrite(handle,Buffer,SizeOf(Buffer),AWrite);}
  68.  
  69. PROCEDURE fClose( fHandle :WORD );
  70.                          { Routine to close file 'fHandle'. This updates}
  71.                          { the directory time and size enteries.        }
  72.                          { Uses Int 21h/AH=3Eh.                         }
  73.                          { usage :                                      }
  74.                          {  fClose(handle);                             }
  75.  
  76. PROCEDURE fReset(  fHandle :WORD );
  77.                          { Routine to reset file position pointer to the}
  78.                          { beginning of 'fHandle'.                      }
  79.                          { Uses Int 21h/AH=42h.                         }
  80.                          { usage :                                      }
  81.                          {  fReset(handle);                             }
  82.  
  83. PROCEDURE fAppend( fHandle :WORD );
  84.                          { Routine to move the File position pointer of }
  85.                          { 'fHandle' to the end of the file. Any further}
  86.                          { writing is added to the end of the file.     }
  87.                          { Uses Int 21h/AH=42h.                         }
  88.                          { usage :                                      }
  89.                          {  fAppend(handle);                            }
  90.  
  91. PROCEDURE fSeek( fHandle :WORD; fOfs :LONGINT );
  92.                          { Routine to move the file position pointer for}
  93.                          { 'fHandle' to 'fOfs'. 'fOfs' is the actual    }
  94.                          { byte position in the file to move to.        }
  95.                          { Uses Int 21h/AH=42h.                         }
  96.                          { usage :                                      }
  97.                          {  fSeek(handle,1023);                         }
  98.  
  99. PROCEDURE fErase( fName :STRING );
  100.                          { Routine to erase 'fName'.                    }
  101.                          { Uses Int 21h/AH=41h.                         }
  102.                          { usage :                                      }
  103.                          {  fErase('Temp.Dat');                         }
  104.  
  105. FUNCTION  fPos( fHandle :WORD ) :LONGINT;
  106.                          { Routine to return the current position within}
  107.                          { 'fHandle'.                                   }
  108.                          { Uses Int 21h/AH=42.                          }
  109.                          { usage :                                      }
  110.                          {  CurPos := fPos(handle);                     }
  111.  
  112. FUNCTION  fEof( fHandle :WORD ) :BOOLEAN;
  113.                          { Routine to determine whether or not we're    }
  114.                          { currently at the end of file 'fHandle'.      }
  115.                          { usage :                                      }
  116.                          {  IsEnd := fEof(handle);                      }
  117.  
  118. FUNCTION  fExist( fName :STRING ) :BOOLEAN;
  119.                          { Routine to determine whether or not 'fName'  }
  120.                          { exists.                                      }
  121.                          { usage :                                      }
  122.                          {  Exist := fExist('Temp.Dat');                }
  123.  
  124. FUNCTION  fGetAttr( fName :STRING ) :BYTE;
  125.                          { Routine to return the current file attribute }
  126.                          { of 'fName'.                                  }
  127.                          { Uses Int 21h/AH=43h,AL=00h.                  }
  128.                          { usage :                                      }
  129.                          {  CurAttr := fGetAttr('Temp.Dat');            }
  130.  
  131. PROCEDURE fSetAttr( fName :STRING; NAttr :BYTE );
  132.                          { Routine to set file attribute of 'fName' to  }
  133.                          { 'NAttr'.                                     }
  134.                          { Uses Int 21h/AH=43h,AL=01h.                  }
  135.                          { usage :                                      }
  136.                          {  fSetAttr('Temp.Dat',aArchive OR aReadOnly); }
  137.  
  138. PROCEDURE fSetVerify( On_Off :BOOLEAN );
  139.                          { Routine to set the DOS verify flag ON or OFF.}
  140.                          { depending on 'On_Off'.                       }
  141.                          { TRUE = ON, FALSE = OFF.                      }
  142.                          { Uses Int 21h/AH=2Eh.                         }
  143.                          { usage :                                      }
  144.                          {  fSetVerify( TRUE );                         }
  145.  
  146. FUNCTION  fGetVerify :BOOLEAN;
  147.                          { Routine to return the current state of the   }
  148.                          { DOS verify flag.                             }
  149.                          { Uses Int 21h/AH=54h.                         }
  150.                          { usage :                                      }
  151.                          {  IsVerify := fGetVerify;                     }
  152.  
  153. FUNCTION  fSize( fHandle :WORD ) :LONGINT;
  154.                          { Routine to determine the size in bytes of    }
  155.                          { 'fHandle'.                                   }
  156.                          { usage :                                      }
  157.                          {  CurSize := fSize(handle);                   }
  158.  
  159. PROCEDURE fFlush( fHandle :WORD );
  160.                          { Flushes any File buffers for 'fHandle'       }
  161.                          { immediately and updates the directory entry. }
  162.                          { Uses Int 21h/AH=68h.                         }
  163.                          { usage :                                      }
  164.                          {  fFlush(handle);                             }
  165.  
  166. PROCEDURE fLock( fHandle :WORD; LockInf :LockType; StartOfs,Len :LONGINT );
  167.                          { Routine to lock/unlock parts of a open file.  }
  168.                          { Locking or unlock is determined by 'LockInf'. }
  169.                          { Uses Int 21h/AH=5Ch.                          }
  170.                          { usage :                                       }
  171.                          {  fLock(handle,Lock,1000,500);                 }
  172. {***********************************************************************}
  173. IMPLEMENTATION
  174.  
  175.  
  176. PROCEDURE ASCIIZ( VAR fName :STRING ); ASSEMBLER;
  177.                          { Routine to add a NULL to a string to make it }
  178.                          { ASCIIZ compatible.                           }
  179.                          { File routines automatically call this routine}
  180. ASM
  181.   Push DS                       { Push DS onto the stack.               }
  182.   LDS DI,fname                  { Point DS:DI ---> fName.               }
  183.   Xor BX,BX                     { Clear BX.                             }
  184.   Mov BL,BYTE PTR DS:[DI]       { Load length of string into BL.        }
  185.   Inc BL                        { Point to char after last one in name. }
  186.   Mov BYTE PTR DS:[DI+BX],0     { Now make it a ASCIIZ string.          }
  187.   Pop DS                        { Pop DS off the stack.                 }
  188. END;{ASCIIZ}
  189.  
  190. FUNCTION  fCreate( fName :STRING; Attr :BYTE ) :WORD;
  191.                          { Routine to Create 'fName' with an attribute  }
  192.                          { of 'Attr'. If the file already exists then it}
  193.                          { will be truncated to a zero length file.     }
  194.                          { Returns a WORD value containing the  handle. }
  195.                          { Uses Int 21h/AH=3Ch.                         }
  196. BEGIN
  197.   ASCIIZ(fName);                { Convert fName to an ASCIIZ string.    }
  198.   ASM
  199.     Push DS                     { Push DS Onto stack.                   }
  200.     Mov fError,0                { Clear Error Flag.                     }
  201.     Mov AX,SS                   { Load AX with SS.                      }
  202.     Mov DS,AX                   { Now load that value into DS.          }
  203.     Lea DX,fName                { Now load DX with the offset of DX.    }
  204.     Inc DX                      { Move past length byte.                }
  205.     Xor CH,CH                   { Clear High byte of CX.                }
  206.     Mov CL,Attr                 { Load attribute to give new file.      }
  207.     Mov AH,$3C                  { Function to create a file.            }
  208.     Int $21                     { Call dos to create file.              }
  209.     Jnc @Exit                   { If no error exit.                     }
  210.     Mov fError,AX               { If there was an  error save it.       }
  211.   @Exit:
  212.     Mov @Result,AX              { Return proper result to user.         }
  213.     Pop DS                      { Pop DS Off the Stack.                 }
  214.   END;
  215. END;{fCreate}
  216.  
  217. FUNCTION  fOpen( fName :STRING; Mode :BYTE ) :WORD;
  218.                          { Routine to open already existing file defined}
  219.                          { in 'fName' with an opening mode of 'Mode'.   }
  220.                          { Returns a WORD value containing the  handle. }
  221.                          { Uses Int 21h/AH=3Dh.                         }
  222. BEGIN
  223.   ASCIIZ(fName);                { Convert fName to an ASCIIZ string.    }
  224.   ASM
  225.     Push DS                     { Push DS onto stack.                   }
  226.     Mov fError,0                { Clear Error Flag.                     }
  227.     Mov AX,SS                   { Load AX with SS.                      }
  228.     Mov DS,AX                   { Now load that value into DS.          }
  229.     Lea DX,fName                { Now load DX with the offset of DX.    }
  230.     Inc DX                      { Move past length byte.                }
  231.     Mov AL,Mode                 { File Opening mode.                    }
  232.     Mov AH,$3D                  { Function to open a file.              }
  233.     Int $21                     { Call dos to open file.                }
  234.     Jnc @Exit                   { If no error exit.                     }
  235.     Mov fError,AX               { If there was an  error save it.       }
  236.   @Exit:
  237.     Mov @Result,AX              { Return proper result to user.         }
  238.     Pop DS                      { Restore DS from stack.                }
  239.   END;
  240. END;{fOpen}
  241.  
  242. PROCEDURE fRead( fHandle :WORD; VAR Buff; NTRead:WORD; VAR ARead :WORD );
  243. ASSEMBLER;               { Reads 'NTRead' bytes of data from 'fHandle'  }
  244.                          { and puts it in 'Buff'. The actually amount   }
  245.                          { of bytes read is returned in 'ARead'.        }
  246.                          { Uses Int 21h/AH=3Fh.                         }
  247. ASM
  248.   Push DS                       { Push DS onto the stack.               }
  249.   Mov fError,0                  { Clear Error flag.                     }
  250.   Mov AH,$3F                    { Function to read from a file.         }
  251.   Mov BX,fHandle                { load handle of file to read.          }
  252.   Mov CX,NTRead                 { # of bytes to read.                   }
  253.   LDS DX,Buff                   { Point DS:DX to buffer.                }
  254.   Int $21                       { Call Dos to read file.                }
  255.   LDS DI,ARead                  { Point to amount read.                 }
  256.   Mov WORD PTR DS:[DI],AX       { Save amount actually read.            }
  257.   Jnc @Exit                     { if there was no error exit.           }
  258.   Mov fError,AX                 { If there was Save error code.         }
  259. @Exit:
  260.   Pop DS                        { Pop DS off the stack.                 }
  261. END;{fRead}
  262.  
  263. PROCEDURE fWrite( fHandle :WORD; VAR Buff; NTWrite:WORD; VAR AWrite :WORD );
  264. ASSEMBLER;               { Writes 'NTWrite' bytes of info from 'Buff'   }
  265.                          { to 'fHandle'. The actually amount written is }
  266.                          { returned in 'AWrite'.                        }
  267.                          { Uses Int 21h/AH=40h.                         }
  268. ASM
  269.   Push DS                       { Push DS onto the stack.               }
  270.   Mov fError,0                  { Clear Error flag.                     }
  271.   Mov AH,$40                    { Function to write to file.            }
  272.   Mov BX,fHandle                { Handle of file to write to.           }
  273.   Mov CX,NTWrite                { # of bytes to read.                   }
  274.   LDS DX,Buff                   { Point DS:DX -> Buffer.                }
  275.   Int $21                       { Call Dos to write to file.            }
  276.   LDS DI,AWrite                 { Point to amount write.                }
  277.   Mov WORD PTR DS:[DI],AX       { Save amount actually written.         }
  278.   Jnc @Exit                     { If there was no error exit.           }
  279.   Mov fError,AX                 { if there was save error code.         }
  280. @Exit:
  281.   Pop DS                        { Pop DS off the stack.                 }
  282. END;{fWrite}
  283.  
  284. PROCEDURE fClose( fHandle :WORD ); ASSEMBLER;
  285.                          { Routine to close file 'fHandle'. This updates}
  286.                          { the directory time and size enteries.        }
  287.                          { Uses Int 21h/AH=3Eh.                         }
  288. ASM
  289.   Mov fError,0                  { Clear Error flag                      }
  290.   Mov AH,$3E                    { Function to close file                }
  291.   Mov BX,fHandle                { load handle of file to close          }
  292.   Int $21                       { call Dos to close file                }
  293.   Jnc @Exit                     { If there was no error exit            }
  294.   Mov fError,AX                 { if there was save error code          }
  295. @Exit:
  296. END;{fClose}
  297.  
  298. PROCEDURE fReset( fHandle :WORD ); ASSEMBLER;
  299.                          { Routine to reset file position pointer to the}
  300.                          { beginning of 'fHandle'.                      }
  301.                          { Uses Int 21h/AH=42h.                         }
  302. ASM
  303.   Mov fError,0                  { Clear error flag.                     }
  304.   Mov AH,$42                    { Function to move file pointer.        }
  305.   Mov BX,fHandle                { Handle of file.                       }
  306.   Mov AL,0                      { Offset relative to begining.          }
  307.   Mov CX,0                      { CX:DX = offset from begining of file  }
  308.   Mov DX,0                      { to move to.                           }
  309.   Int $21                       { Call dos to change file pointer.      }
  310.   Jnc @Exit                     { If there was no error exit.           }
  311.   Mov fError,AX                 { If there was save error code.         }
  312. @Exit:
  313. END;{fReset}
  314.  
  315. PROCEDURE fAppend( fHandle :WORD); ASSEMBLER;
  316.                          { Routine to move the File position pointer of }
  317.                          { 'fHandle' to the end of the file. Any further}
  318.                          { writing is added to the end of the file.     }
  319.                          { Uses Int 21h/AH=42h.                         }
  320. ASM
  321.   Mov fError,0                  { Clear error flag.                     }
  322.   Mov AH,$42                    { Function to change file ptr position. }
  323.   Mov BX,fHandle                { handle of file to change.             }
  324.   Mov AL,$02                    { Change relative to end of file.       }
  325.   Mov CX,0                      { CX:DX = offset from end of file       }
  326.   Mov DX,0                      { to move to.                           }
  327.   Int $21                       { Call dos to move file ptr.            }
  328.   Jnc @Exit                     { If there was no error exit.           }
  329.   Mov fError,AX                 { If there was save error code.         }
  330. @Exit:
  331. END;{fAppend}
  332.  
  333. PROCEDURE fSeek( fHandle :WORD; fOfs :LONGINT ); ASSEMBLER;
  334.                          { Routine to move the file position pointer for}
  335.                          { 'fHandle' to 'fOfs'. 'fOfs' is the actual    }
  336.                          { byte position in the file to move to.        }
  337.                          { Uses Int 21h/AH=42h.                         }
  338. ASM
  339.   Mov fError,0                  { Clear error flag.                     }
  340.   Mov AH,$42                    { Function to change file ptr position. }
  341.   Mov BX,fHandle                { handle of file to change.             }
  342.   Mov AL,$00                    { Change relative to start of file.     }
  343.   Mov CX,fOfs[2].WORD           { CX:DX = offset from start of file     }
  344.   Mov DX,fOfs.WORD              { to move to.                           }
  345.   Int $21                       { Call dos to move file ptr.            }
  346.   Jnc @Exit                     { If there was no error exit.           }
  347.   Mov fError,AX                 { If there was save error code.         }
  348. @Exit:
  349. END;{fSeek}
  350.  
  351. PROCEDURE fErase( fName :STRING );
  352.                          { Routine to erase 'fName'.                    }
  353.                          { Uses Int 21h/AH=41h.                         }
  354. BEGIN
  355.   ASCIIZ(fName);                { Convert fName to an ASCIIZ string.    }
  356.   ASM
  357.     Push DS                     { Push DS onto the stack.               }
  358.     Mov fError,0                { Clear error flag.                     }
  359.     Mov AX,SS                   { Load AX with SS.                      }
  360.     Mov DS,AX                   { Now load that value into DS.          }
  361.     Lea DX,fName                { Now load DX with the offset of DX.    }
  362.     Inc DX
  363.     Mov AH,$41                  { Function to erase a file.             }
  364.     Int $21                     { Call dos to erase file.               }
  365.     Jnc @Exit                   { If no error exit.                     }
  366.     Mov fError,AX               { if there was error save error code.   }
  367.   @Exit:
  368.     Pop DS                      { Pop DS off the stack.                 }
  369.   END;
  370. END;{fErase}
  371.  
  372. FUNCTION  fPos( fHandle :WORD ) :LONGINT; ASSEMBLER;
  373.                          { Routine to return the current position within}
  374.                          { 'fHandle'.                                   }
  375.                          { Uses Int 21h/AH=42.                          }
  376. ASM
  377.   Mov fError,0                  { Clear error flag.                     }
  378.   Mov AH,$42                    { Function to move file pointer.        }
  379.   Mov BX,fHandle                { Handle of file.                       }
  380.   Mov AL,1                      { Offset relative to current pos.       }
  381.   Mov CX,0                      { CX:DX = offset from current position  }
  382.   Mov DX,0                      { to move to.                           }
  383.   Int $21                       { Call dos to change file pointer.      }
  384.   Jnc @Exit                     { If there was no error return result.  }
  385.   Mov fError,AX                 { If there was save error code.         }
  386. @Exit:                          { Int already returns DX:AX as file pos.}
  387. END;{fPos}
  388.  
  389. FUNCTION  fEof( fHandle :WORD ) :BOOLEAN;
  390.                          { Routine to determine whether or not we're    }
  391.                          { currently at the end of file 'fHandle'.      }
  392. VAR
  393.    CurOfs :LONGINT;             { current file offset.                  }
  394. BEGIN
  395.   CurOfs := fPos(fHandle);      { Save Current Pos.                     }
  396.   fAppend(fHandle);             { Move to the end of the file.          }
  397.   fEof := (CurOfs = fPos(fHandle)); { was current pos = end pos?.       }
  398.   fSeek(fHandle,CurOfs);        { Restore to original file position.    }
  399. END;{fEof}
  400.  
  401. FUNCTION  fExist( fName :STRING ) :BOOLEAN;
  402.                          { Routine to determine whether or not 'fName'  }
  403.                          { exists.                                      }
  404. BEGIN
  405.   fExist := ( FSearch(fName,'') <> '');
  406. END;{fExist}
  407.  
  408. FUNCTION  fGetAttr( fName :STRING ) :BYTE;
  409.                          { Routine to return the current file attribute }
  410.                          { of 'fName'.                                  }
  411.                          { Uses Int 21h/AH=43h,AL=00h.                  }
  412. BEGIN
  413.   ASCIIZ(fName);                { Convert fName to an ASCIIZ string.    }
  414.   ASM
  415.     Push DS                     { Push DS onto the stack.               }
  416.     Mov fError,0                { Clear error flag.                     }
  417.     Mov AX,SS                   { Load AX with SS.                      }
  418.     Mov DS,AX                   { Now load that value into DS.          }
  419.     Lea DX,fName                { Now load DX with the offset of DX.    }
  420.     Inc DX
  421.     Mov AX,$4300                { Function to Get file Attrib.          }
  422.     Int $21                     { Call dos to get attr.                 }
  423.     Jnc @Success                { If no error return proper info.       }
  424.     Mov fError,AX               { if there was error save error code.   }
  425.   @Success:
  426.     Mov AX,CX
  427.     Mov @Result,AL              { Return proper result to user.         }
  428.     Pop DS                      { Pop DS off the stack.                 }
  429.   END;
  430. END;{fGetAttr}
  431.  
  432. PROCEDURE fSetAttr( fName :STRING; NAttr :BYTE );
  433.                          { Routine to set file attribute of 'fName' to  }
  434.                          { 'NAttr'.                                     }
  435.                          { Uses Int 21h/AH=43h,AL=01h.                  }
  436. BEGIN
  437.   ASCIIZ(fName);                { Convert fName to an ASCIIZ string.    }
  438.   ASM
  439.     Push DS                     { Push DS onto the stack.               }
  440.     Mov fError,0                { Clear error flag.                     }
  441.     Mov AX,SS                   { Load AX with SS.                      }
  442.     Mov DS,AX                   { Now load that value into DS.          }
  443.     Lea DX,fName                { Now load DX with the offset of DX.    }
  444.     Inc DX                      { Point to first char after length byte.}
  445.     Xor CX,CX                   { Clear CX.                             }
  446.     Mov CL,NAttr                { Load New attribute byte.              }
  447.     Mov AX,$4301                { Function to Set file Attrib.          }
  448.     Int $21                     { Call dos to set attrib.               }
  449.     Jnc @Exit                   { If no error exit.                     }
  450.     Mov fError,AX               { if there was error save error code.   }
  451.   @Exit:
  452.     Pop DS                      { Pop DS off the stack.                 }
  453.   END;
  454. END;{fSetAttr}
  455.  
  456. PROCEDURE fSetVerify( On_Off :BOOLEAN ); ASSEMBLER;
  457.                          { Routine to set the DOS verify flag ON or OFF.}
  458.                          { depending on 'On_Off'.                       }
  459.                          { TRUE = ON, FALSE = OFF.                      }
  460.                          { Uses Int 21h/AH=2Eh.                         }
  461. ASM
  462.   Mov AH,$2E                        {  Interrupt Subfunction.               }
  463.   Mov DL,0                      {  Clear DL.                            }
  464.   Mov AL,On_Off                        {  0(FALSE) = off, 1(TRUE) = on.        }
  465.   Int $21                        {  Call Dos.                            }
  466. END;{fSetVerify}
  467.  
  468. FUNCTION  fGetVerify :BOOLEAN; ASSEMBLER;
  469.                          { Routine to return the current state of the   }
  470.                          { DOS verify flag.                             }
  471.                          { Uses Int 21h/AH=54h.                         }
  472. ASM
  473.   Mov AH,$54                        {  Interrupt Subfunction                }
  474.   Int $21                        {  Call Dos                             }
  475. END;{fGetVerify}
  476.  
  477. FUNCTION  fSize( fHandle :WORD ) :LONGINT;
  478.                          { Routine to determine the size in bytes of    }
  479.                          { 'fHandle'.                                   }
  480. VAR
  481.    CurOfs :LONGINT;             { Holds original file pointer.          }
  482. BEGIN
  483.   CurOfs := fPos(fHandle);      { Save current file pointer.            }
  484.   fAppend(fHandle);             { Move to end of file.                  }
  485.   fSize := fPos(fHandle);       { Save current pos which equals size.   }
  486.   fSeek(fHandle,CurOfs);        { Restore original file pos.            }
  487. END;{fSize}
  488.  
  489. PROCEDURE fFlush( fHandle :WORD ); ASSEMBLER;
  490.                          { Flushes any File buffers for 'fHandle'       }
  491.                          { immediately and updates the directory entry. }
  492.                          { Uses Int 21h/AH=68h.                         }
  493. ASM
  494.   Mov fError,0                  { Clear error flag.                     }
  495.   Mov AH,$68                    { Function to Commit file to disk.      }
  496.   Mov BX,fHandle                { Load handle of file to Commit.        }
  497.   Int $21                       { Call dos to flush file.               }
  498.   Jnc @Exit                     { If no error exit.                     }
  499.   Mov fError,AX                 { if there was error save error code.   }
  500. @Exit:
  501. END;{fSetAttr}
  502.  
  503. PROCEDURE fLock( fHandle :WORD; LockInf :LockType; StartOfs,Len :LONGINT );
  504.                          { Routine to lock/unlock parts of a open file.  }
  505. ASSEMBLER;               { Locking or unlock is determined by 'LockInf'. }
  506.                          { Uses Int 21h/AH=5Ch.                          }
  507.  
  508. ASM
  509.   Mov fError,0                  { Clear Error Flag.                     }
  510.   Mov AH,$5C                    { Function to lock/unlock part of a file.}
  511.   Mov AL,LockInf                { Load whether to lock/unlock file area.}
  512.   Mov BX,fHandle                { Handle of file to lock.               }
  513.   Mov CX,StartOfs.WORD[0]       { Load StartOfs Into  CX:DX.            }
  514.   Mov DX,StartOfs.WORD[2]
  515.   Mov SI,Len.WORD[0]            { Load Len Into SI:DI.                  }
  516.   Mov DI,Len.WORD[2]
  517.   Int $21                       { Call dos to lock area.                }
  518.   Jnc @Exit                     { If no error exit.                     }
  519.   Mov fError,AX                 { If there was an  error save it.       }
  520. @Exit:
  521. END;{fLock}
  522.  
  523. BEGIN
  524. END.{FileIO}
  525.